package com.lqjava.flowable.beans.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
 * 文件类型枚举
 * 主要功能: 判断后缀属于哪种文件类型
 * @author lq 2021年3月21日 18:35:33
 */
@Getter
@AllArgsConstructor
public enum FileTypeEnum{

	FOLDER("FOLDER", "文件夹"){
		
		@Override
		public List<String> getIncludedList() {
			return Collections.singletonList("");
		}
	},
	IMGAE("IMGAE", "图片"){
		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("JPG","JPGE","PNG","WEBP","GIF");
		}
	},
	
	TXT("TXT",  "文本"){

		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("TXT");
		}
	},
	
	WORD("WORD",  "word"){
		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("DOC","DOCX");
		}
	},
	EXCEL("EXCEL",  "表格"){

		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("XLS","XLSX");
		}
	},
	PPT("PPT",  "ppt"){

		
		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("PPT","PPTX");
		}
	},
	VSD("VSD",  "流程图"){

		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("VSD","VSDX");
		}
	},
	
	COMPRESS("COMPRESS",  "压缩文件"){

		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("ZIP","RAR","7Z","TAR");
		}
	},
	
	AUDIO ("AUDIO",  "音频"){

		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("CDA","WAV","MP3","MP3 PRO","WMA");
		}
	},
	VIDEO ("VIDEO",  "视频"){

		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("AVI","MOV","MOV/QT","QT","ASF","RM","ACC","MPEG","RMVB","MP4");
		}
	},
	
	OTHER("OTHER",  "其他"){

		@Override
		public List<String> getIncludedList() {
			return Arrays.asList("");
		}
	},
	;
	
	private String value;
	private String explain;

	public List<String> getIncludedList(){
		return new ArrayList<>();
	}
	
	public static FileTypeEnum getFileType(String fileName){
		FileTypeEnum type = FileTypeEnum.OTHER;
		String[] split = fileName.split("\\.");
		if(split.length > 1){
			String last = split[split.length - 1];
			last = last.toUpperCase();
			FileTypeEnum[] values = values();
			for (FileTypeEnum fileType : values) {
				List<String> includedList = fileType.getIncludedList();
				if(includedList.contains(last)){
					type = fileType;
					break;
				}
			}
		}
		return type;
	}

}
